package com.shangqing.web.controller.thunder;

import com.shangqing.common.annotation.Log;
import com.shangqing.common.core.controller.BaseController;
import com.shangqing.common.core.domain.AjaxResult;
import com.shangqing.system.service.thunder.ThunderDisasterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/thunder")
public class ThunderController extends BaseController {
    @Autowired
    ThunderDisasterService thunderDisasterService;
    @Autowired
    RestTemplate restTemplate;
    @Log(title = "雷电灾情信息")
    @PreAuthorize("@ss.hasPermi('thunder:list')")
    @PostMapping("/list/{Num}")
    public AjaxResult list(@PathVariable("Num")String Num){
        return AjaxResult.success("成功",thunderDisasterService.findAllThunderList(Num));
    }
    @Log(title = "雷电全区灾情统计")
    @PostMapping("/thunderList/{year}/{quarter}")
    public AjaxResult findHailQuarterList(@PathVariable(value = "year",required = false)String year,
                                          @PathVariable(value = "quarter",required = false)String quarter) {
        Map map=new HashMap();
        Integer Num= thunderDisasterService.findThunderQuarterList(year, quarter);
        map.put("thunderNum",Num);
        map.put("thunderYear",year);
        map.put("thunderQuarter",quarter);
        return AjaxResult.success("成功",map);
    }
    @Log(title = "各区雷电灾害发生占比")
    @PostMapping("/thunderCount/{year}/{quarter}")
    public AjaxResult findCountHailByCity(@PathVariable(value = "year",required = false)String year,
                                          @PathVariable(value = "quarter",required = false)String quarter){
        logger.info("=========参数========"+year+"===="+quarter);
        return AjaxResult.success("成功",thunderDisasterService.findCountThunderByCity(year, quarter));
    }
    @Log(title = "本地实时天气")
    @GetMapping("/thunder/Weather")
    public AjaxResult showWeather(){
        /*高德API接口*/
        String weatherUrl = "https://restapi.amap.com/v3/weather/weatherInfo?city=640106&key=ed8913582dbbc7b27152c793cfac49b7";
        ResponseEntity<String> weatherEntity = restTemplate.getForEntity(weatherUrl, String.class);
        String weatherBody = weatherEntity.getBody();
        return AjaxResult.success("成功",weatherBody);
    }
    @Log(title = "各区雷电灾情统计")
    @PostMapping("/thunder/RegionalStatistics")
    public AjaxResult regionalStatistics(){
        return AjaxResult.success("成功",thunderDisasterService.findRegionalDisasterStatistics());
    }
}
